//
//  BigDesktopViewController.m
//  GaojiaoSNS
//
//  Created by apple on 13-10-30.
//  Copyright (c) 2013年 EbolaPro. All rights reserved.
//

#import "BigDesktopViewController.h"
#import "tooles.h"
#import <Colours.h>
#import "WubiExtraViewController.h"

@interface BigDesktopViewController ()<UICollectionViewDataSource,UICollectionViewDelegate>

@property (strong, nonatomic) IBOutlet UICollectionView *collectionView;
@property (nonatomic,strong) NSArray *itemsArray;
@property(nonatomic,assign)BOOL myIMSelected;//标记点击动作（IM）
@end

@implementation BigDesktopViewController

@synthesize itemsArray;

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
			self.view.backgroundColor = [UIColor honeydewColor];
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    UINib *cellNib = [UINib nibWithNibName:@"BigDesktopCell" bundle:nil];
    [self.collectionView registerNib:cellNib forCellWithReuseIdentifier:@"BDCCell"];
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
-(void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:animated];
    [[NSNotificationCenter defaultCenter] removeObserver:self name:@"DidAuthenticate" object:nil];
}

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    self.itemsArray = nil;
    self.myIMSelected=NO;
    self.itemsArray = [NSArray arrayWithObjects:@"打字游戏",@"四根字取码",@"速成经验",@"直观取码",@"选择输入法",@"五笔很简单",@"拆分部首",@"容错码",nil];
    [self.collectionView reloadData];
}

- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView{
    return 1;
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
    return self.itemsArray.count;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    
    static NSString *cellIdentifier = @"BDCCell";
    UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:cellIdentifier forIndexPath:indexPath];
    NSString *selectedStr = [self.itemsArray objectAtIndex:indexPath.row];
    UILabel *titleLabel = (UILabel *)[cell viewWithTag:10];
    titleLabel.text = selectedStr;
    UIImageView *imageVie = (UIImageView*)[cell viewWithTag:11];
    imageVie.image = [UIImage imageNamed:[NSString stringWithFormat:@"list%ld",indexPath.row%4 + 1]];
    return cell;
}

-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
    NSString *selectedStr = [self.itemsArray objectAtIndex:indexPath.row];
    WubiExtraViewController *vc = [[WubiExtraViewController alloc] initWithExtraIndex:indexPath.row + 1];
    vc.title = selectedStr;
    [self.navigationController pushViewController:vc animated:YES];
    
}
@end
